package future.java;

import java.util.concurrent.*;

public class RealData implements Callable<String> {

    private String param;

    public RealData(String param) {
        this.param = param;
    }

    @Override
    public String call() throws Exception {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 10; i++) {
            sb.append(param);
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {}
        }
        return sb.toString();
    }

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        FutureTask<String> future = new FutureTask<>(new RealData("a"));
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.submit(future);
        System.out.println("任务提价成功");
        Thread.sleep(1000);

        System.out.println("数据=" + future.get());
    }
}
